package com.controller;

import com.service.ChatRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/chatroom")
public class ChatRoomController {
    @Autowired
    private ChatRoomService chatRoomService;

    @PostMapping("/join")
    public List<String> joinRoom(@RequestParam String roomId, @RequestParam String userId) {
        List<String> otherUsers = chatRoomService.joinRoom(roomId, userId);
        System.out.println("User joined: " + userId + ". Other users in the room: " + otherUsers);
        return otherUsers;
    }
    @PostMapping("/leave")
    public List<String> leaveRoom(@RequestParam String roomId, @RequestParam String userId) {
        List<String> otherUsers = chatRoomService.leaveRoom(roomId, userId);
        System.out.println("User left: " + userId + ". Other users in the room: " + otherUsers);
        return otherUsers;
    }



}
